// miniprogram/pages/taskPage/taskPage.js
var http = require('../../utils/httpUtil.js')
var state = require('../../utils/stateUtil.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    taskList: [],
    type: [],
    imagesrc1: "../../images/gry.png",
    imagesrc2: "../../images/Triangle.png",
    textColor: "#2780F4",
    textColor1: "#666666",
    showModal: false,
    timeModal: false,
    selected: [false, false, false, false, false, false, false],
    timeTitle: ["流入时间最近", "流入时间最远", "报案时间最近", "报案时间最远"],
    timeIndx: 0,
    state: [],
    PageIndex:1,
    isNoMore:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getDate();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  openAnjian: function(event) {
    var anjian = event.currentTarget.dataset.anjian;
    wx.navigateTo({
      url: '/pages/tixi/tixi?anjian=' + anjian.ReportId + "&SurveyTaskId=" + anjian.TaskId,
    })
    console.log("案件", anjian)
  },
  //时间
  binOrderTime: function(event) {
    this.setData({
      textColor: "#2780F4",
      imagesrc2: "../../images/Triangle.png",
      textColor1: "#666666",
      imagesrc1: "../../images/gry.png",
      timeModal: true,
    })
  },
  //状态
  binOrderState: function(event) {
    this.setData({
      textColor: "#666666",
      imagesrc2: "../../images/gry.png",
      textColor1: "#2780F4",
      imagesrc1: "../../images/Triangle.png",
      showModal: true,
    })
  },
  //对话框取消按钮
  modalCancel: function(event) {
    this.setData({
      showModal: false
    })
  },
  // 对话框确定按钮
  modalConfirm: function(event) {
    this.setData({
      showModal: false
    })
    this.data.state = state.state(this.data.selected);
    this.data.taskList = [];
    this.data.PageIndex = 1;
    this.getDate();
  },
  //时间对话框取消
  timeCancel: function(event) {
    this.setData({
      timeModal: false
    })
  },
  //时间对话框确定
  timeConfirm: function(event) {
    this.setData({
      timeModal: false
    })
    this.data.taskList = [];
    this.data.PageIndex = 1;
    this.getDate();
  },
  //流入时间点击事件
  timeLook: function(event) {

  },
  //状态的点击事件
  chakan: function(evnet) {
    var index = evnet.currentTarget.dataset.index;
    let selectIndex = this.data.selected;
    selectIndex[index] = !selectIndex[index];
    this.setData({
      selected: selectIndex
    })
  },
  binTime: function(event) {
    var index = event.currentTarget.dataset.time;
    console.log("jsahdsdfjhsdjfhjshfjs", index)
    this.setData({
      timeIndx: index
    })
  },
  /**
   * 上拉加载
   */
  onReachBottom: function() {
    this.data.PageIndex = this.data.PageIndex+1;
    this.getDate();
  },
  /**
   * 下拉刷新
   */
  onPullDownRefresh: function() {
    this.data.taskList = [];
    this.data.PageIndex = 1;
    this.getDate();
  },
  getDate: function() {
    var that = this;
    var param = {}
    param.PageIndex = this.data.PageIndex
    param.PageSize = 15
    param.TaskStatus = this.data.state
    param.OrderFlag = this.data.timeIndx
    http.PostHttp("Survey/GetTaskList", param, function(res) {
      if (res.Code == 1) {
        if (res.Data.Value.length != 0){
          that.setData({
            taskList: that.data.taskList.concat(res.Data.Value),
            isNoMore:false
          })
        }else{
          that.setData({
            isNoMore: true
          })
        }
        console.log("获取到的任务列表", res.Data.Value)
      } else {
        wx.showToast({
          title: res.Message,
        })
      }
    })
  }
})